package com.chengyu.core.controller.floor;

import com.chengyu.core.component.DemoStationForbid;
import com.chengyu.core.component.OperationLog;
import com.chengyu.core.controller.AdminBaseController;
import com.chengyu.core.entity.CommonPage;
import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.FloorMobileTemplate;
import com.chengyu.core.model.HomeConfig;
import com.chengyu.core.service.floor.FloorService;
import com.chengyu.core.service.homeFloor.HomeFloorService;
import com.chengyu.core.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(tags = "装修商城")
@Controller
@RequestMapping("/system")
public class HomeFloorController extends AdminBaseController {
	
	@Autowired
	private HomeFloorService homeFloorService;
	
	@ApiOperation(value = "装修模板列表")
	@ResponseBody
	@RequestMapping(value="/home/floor/getList", method=RequestMethod.GET)
	public CommonResult<CommonPage<HomeConfig>> getList(
			Integer shopId,
			Integer type,
			@RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) throws ServiceException {
		
		List<HomeConfig> list = homeFloorService.listHomeFloorConfig(type, page, pageSize);
		return CommonResult.success(CommonPage.restPage(list));
	}

	@OperationLog
	@ApiOperation(value = "添加编辑装修模板")
	@ResponseBody
	@RequestMapping(value="/home/floor/editSubmit", method=RequestMethod.POST)
	public CommonResult<String> editSubmit(HomeConfig config) throws ServiceException {
		homeFloorService.editUpdate(config);
		return CommonResult.success(null);
	}

	@DemoStationForbid
	@OperationLog
	@ApiOperation(value = "删除装修模板")
	@ResponseBody
	@RequestMapping(value="/home/floor/delete", method=RequestMethod.POST)
	public CommonResult<String> delete(String ids) throws ServiceException {
		if (StringUtils.isNotBlank(ids)){
			for (String s : ids.split(",")) {
				homeFloorService.del(Integer.parseInt(s));
			}
		}else{
			throw new ServiceException("id不能为空");
		}

		return CommonResult.success(null);
	}


}